#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
using namespace std;
const int N = 1e5 + 10;

int a[N];
int b[N];
int main() {

	string str;
	cin >> str;
	int n = str.size();
	if (str[0] == str[n - 1]) {
		cout << 1 << endl;
		return 0;
	}
	int l = 0;
	int r = 0;
	for (int i = 0; i < str.size(); i++) {
		if (str[i] == '(')a[i+1]=-1,l++;
		else a[i + 1] = 1,r++;
		
	}
	for (int i = 1; i <= str.size(); i++) {
		b[i] = b[i - 1] + a[i];

	}
	if (b[n] == 0) {
		cout << 0 << endl;
		return 0;
	}
	int ans = 0;
	char u = '(';
	if (r > l)u = ')';
	
	for (int i = 2; i < n; i++) {
		if (str[i - 1] == u) {
			if (u == '(') {
				if ((b[i - 1] + 1 == 0 && b[n] - b[i] == 0) || (b[i - 1] + 1 + b[n] - b[i] == 0&& b[i - 1] + 1<= b[n] - b[i])) {
					ans++;
				}
			}
			else {
				if ((b[i - 1] -1 == 0 && b[n] - b[i] == 0) || (b[i - 1] -1 + b[n] - b[i] == 0 && b[i - 1] - 1 <= b[n] - b[i]))ans++;
			}
		}
	}
	
	cout <<ans<< endl;


	return 0;
}